<?php

define("loglvl", 4);
define("logcat", 1);

if(!defined('IN_refrigeratory')) {
	exit('Access Denied');
}

$operation = $_REQUEST["operation"];
$operations = array("get", "update");
if (!in_array($operation, $operations)){
	echo '{"success":false, "info":"request params invalid"}';
	exit;
}

else if($operation == "get"){
	echo get_json_from_sql("SELECT name , value FROM tb_parameters ORDER BY name");
}


else if($operation == "update"){
	$json = $_REQUEST['jsonData'];
	$arr = json_decode(stripslashes($json),true);
	foreach($arr as $a=>$b){//依次取出数组中元素，$a是元素的键名$b是键值	
		execute_sql("UPDATE tb_parameters SET value = '$b[value]' WHERE name = '$b[name]'");				
	}
	$message = "修改成功";
	echo '{"success": true,"info":"'.$message.'"}'; 
}


function safeJSON_chars($data) { 
    $aux = str_split($data); 
    foreach($aux as $a) { 
        $a1 = urlencode($a); 
        $aa = explode("%", $a1); 
        foreach($aa as $v) { 
            if($v!="") { 
                if(hexdec($v)>127) { 
                $data = str_replace($a,"&#".hexdec($v).";",$data); 
                } 
            } 
        } 
    } 
    return $data; 
} 

?>